package com.taotao.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EasyUIDataGridResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.content.service.ContentService;
import com.taotao.pojo.TbContent;

/**
 * 内容管理
 * 
 * @author Administrator
 *
 */
@Controller
public class ContentController {

	// 1.注入服务
	@Autowired
	private ContentService contentService;

	// $.post("/content/save",$("#contentAddForm").serialize(), function(data){
	@RequestMapping(value = "/content/save", method = RequestMethod.POST)
	@ResponseBody
	public TaotaoResult saveContent(TbContent tbContent) {

		return contentService.addContent(tbContent);
	}

	// method:'get',pageSize:20,url:'/content/query/list',queryParams:{categoryId:0}">
	// @RequestMapping(value="/content/category/list",method=RequestMethod.GET)
	@RequestMapping(value = "/content/query/list", method = RequestMethod.GET)
	@ResponseBody
	public EasyUIDataGridResult showContent(@RequestParam("page") Integer nowPage, Integer rows, long categoryId) {
		return contentService.showContent(nowPage, rows, categoryId);
	}

	// var params = {"ids":ids};
	// $.post("/content/delete",params, function(data){
	@RequestMapping(value = "/content/delete", method = RequestMethod.POST)
	@ResponseBody
	public TaotaoResult deleteContent(String ids) {
		List<Long> list = new ArrayList<Long>();

		for (String str : ids.split(",")) {
			list.add(Long.parseLong(str));
		}

		return contentService.deleteContent(list);
	}
}
